<?php

/*
 * Created by generator
 *
 */

/**
 * Recupere la liste des enregistrements
 * @param object $db database object
 * @return array of data
 */
if (!function_exists('getAlladherentsFromDB')) {
	function getAlladherentsFromDB($db, $orderBy) {
		$sql = "SELECT adhidadh, adhlbnom, adhlbprn, adhtxadr, adhlbtel, adhlbmai, adhlbpho from gyaadh ";
		if( $orderBy != null ) {
			$sql .= "order by " . $orderBy;
		}
		$query = $db->query($sql);

		// recuperer les enregistrements
		$records = array();
		foreach ($query->result_array() as $row) {
			$records[] = $row;
		}
		return $records;
	}
}


/**
 * Insere un nouvel enregistrement
 * @param object $db database object
 * @param string ...
 * @return number identifiant
 */
if (!function_exists('insertNewadherent')) {
	function insertNewadherent($db, $adhlbnom, $adhlbprn, $adhtxadr, $adhlbtel, $adhlbmai, $adhlbpho) {
		$data=array( 'adhlbnom'=>$adhlbnom, 'adhlbprn'=>$adhlbprn, 'adhtxadr'=>$adhtxadr, 'adhlbtel'=>$adhlbtel, 'adhlbmai'=>$adhlbmai, 'adhlbpho'=>$adhlbpho );
		$db->insert('gyaadh',$data);
		return $db->insert_id();
	}
}

/**
 * Mise a jour d'un enregistrement
 */
if (!function_exists('updateadherent')) {
	function updateadherent($db, $adhidadh, $adhlbnom, $adhlbprn, $adhtxadr, $adhlbtel, $adhlbmai) {
		$sql = "update gyaadh set adhlbnom = ?, adhlbprn = ?, adhtxadr = ?, adhlbtel = ?, adhlbmai = ? where adhidadh=?";
		$query = $db->query($sql, array($adhlbnom, $adhlbprn, $adhtxadr, $adhlbtel, $adhlbmai, (int)$adhidadh ));
	}
}


/**
 * Suppression d'un enregistrement
 */
if (!function_exists('deleteadherent')) {
	function deleteadherent($db, $adhidadh) {
		$sql = "delete from gyaadh where adhidadh=?";
		$query = $db->query($sql, array((int)$adhidadh));
	}
}


/**
 * Recupere les informations d'un enregistrement
 * @param object $db database object
 * @param int id de l'enregistrement
 * @return array
 */
if (!function_exists('getadherentRow')) {
	function getadherentRow($db, $adhidadh) {
		$sql = "select adhidadh, adhlbnom, adhlbprn, adhtxadr, adhlbtel, adhlbmai, adhlbpho from gyaadh " .
		"where adhidadh=?";
		$query = $db->query($sql, array((int)$adhidadh));
		if ($query->num_rows() == 0) {
			return null;
		}
		return $query->row_array();
	}
}

	/***************************************************************************
	 * USER DEFINED FUNCTIONS
	 ***************************************************************************/


/**
 * Mise a jour d'une photo
 */
if (!function_exists('updatePhotoAdherent')) {
	function updatePhotoAdherent($db, $adhidadh, $adhlbpho) {
		$sql = "update gyaadh set adhlbpho = ? where adhidadh=?";
		$query = $db->query($sql, array($adhlbpho, (int)$adhidadh ));
	}
}

/**
 * Liste des adhérents d'une activité
 */
if (!function_exists('getAllAdherentsForActiviteFromDB')) {
	function getAllAdherentsForActiviteFromDB($db, $actidact, $orderBy) {
		$sql = "SELECT adhidadh, adhlbnom, adhlbprn, adhtxadr, adhlbtel, adhlbmai, adhlbpho ".
			" from gyaadh LEFT JOIN gyaxaa xaa on (gyaadh.adhidadh = xaa.xaaidadh) ".
			" where xaa.xaaidact = ?";
		if( $orderBy != null ) {
			$sql .= " order by " . $orderBy;
		}
		$query = $db->query($sql, array((int)$actidact));

		// recuperer les enregistrements
		$records = array();
		foreach ($query->result_array() as $row) {
			$records[] = $row;
		}
		return $records;
		
	}
}




?>
